#include <iostream>
#include "matrix.h"
using namespace std;

void matrix::matrixMultiply(int **a, int **b, int **c, int rowA, int colA, int rowB, int colB)
{
	if (colA != rowA)
	{
		cout << "cols of A != rows of B\n Multiplication not possible" << endl;
		return;
	}
	//display the multipication of matrices
	for (int i = 0; i<rowA; i++){
		for (int j = 0; j<colB; j++){
			c[i][j] = 0;
			for (int k = 0; k<colA; k++){
				c[i][j] = c[i][j] + (a[i][k] * a[k][j]);
			}
		}
	}

	cout << "your matrix is" << endl;
	for (int i = 0; i<rowA; i++){
		for (int j = 0; j<colB; j++){
			cout << c[i][j] << " ";
		}
		cout << endl;
	}
}
void matrix::matrixAdd(int **a, int **b, int **sum, int rowA, int colA, int rowB, int colB)
{
	if (rowA != rowB || colA != colB)
	{
		cout << "Rows and columns of both matrices not equal.\n Addition not possible" << endl;
		return;
	}
	for (int c = 0; c < rowA; c++)
		for (int d = 0; d < colA; d++)
			sum[c][d] = a[c][d] + b[c][d];

	cout << "Sum of entered matrices:-\n";

	for (int c = 0; c < rowA; c++)
	{
		for (int d = 0; d < colA; d++)
			cout << sum[c][d] << "\t";

		cout << endl;
	}
}


void matrix::matrixSubtract(int **a, int **b, int **sum, int rowA, int colA, int rowB, int colB)
{
	if (rowA != rowB || colA != colB)
	{
		cout << "Rows and columns of both matrices not equal.\n Subtraction not possible" << endl;
		return;
	}
	for (int c = 0; c < rowA; c++)
		for (int d = 0; d < colA; d++)
			sum[c][d] = a[c][d] - b[c][d];

	cout << "Sum of entered matrices:-\n";

	for (int c = 0; c < rowA; c++)
	{
		for (int d = 0; d < colA; d++)
			cout << sum[c][d] << "\t";

		cout << endl;
	}

}
